﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;

namespace ProjectBuilder
{
    [DbTable("phpdoc_inherited_methods")]
    class InheritedMethods : BaseRefObject
    {
        [DbField("class_id")]
        public long? ClassId { get; set; }

        [DbField("parent_id")]
        public string Parent { get; set; }

        [DbField("distance")]
        public int Distance { get; set; }

        [DbField("method_id")]
        public long? MethodId { get; set; }

        public InheritedMethods(ProjectBuilder.PhpDocTypes.InheritedMethod im,long? classId)
        {
            ClassId = classId;
            Parent = im.Class;
            Distance = im.Distance;
            var parentId = Class.getIdByName(Parent);
            var cmd = new MySqlCommand();
            cmd.CommandText = "SELECT `id` FROM `phpdoc_method` WHERE `name` = '" + im.Name + "' AND `class_id` = " + parentId;
            cmd.CommandType = CommandType.Text;
            cmd.Connection = Globals.Connection;
            var methodId = cmd.ExecuteScalar();
            MethodId = -1;
            if (methodId != null)
                MethodId = long.Parse(methodId.ToString());
        }
    }
}
